package com.haizhi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

@SpringBootApplication
@EnableScheduling
public class Client implements SchedulingConfigurer {

//    private static Logger logger = LoggerFactory.getLogger(Client.class);

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.setScheduler(taskExecutor());
    }

    //开启两个定时任务
    @Bean(destroyMethod = "shutdown")
    public Executor taskExecutor() {
        return Executors.newScheduledThreadPool(2);
    }

    public static void main(String[] args) {
        SpringApplication.run(Client.class, args);
    }

//    @Bean
//    CommandLineRunner files(StorageService storageService) {
//        return (args) -> {
//            // 启动时 初始化目录信息
//            storageService.storageInit();
//        };
//    }

//    @Bean
//    CommandLineRunner downloadTest(DownloadRepository downloadRepository) {
//        return (args) -> {
//            logger.info("H2 downloadTest 测试开始...");
//
//            List<DownloadInfo> downloadInfoList = downloadRepository.findAll();
//
//            downloadInfoList.forEach(downloadInfo -> logger.info(downloadInfo.toString()));
//            logger.info("H2 downloadTest 测试完成...");
//        };
//    }
//
//    @Bean
//    CommandLineRunner uploadTest(UploadRepository uploadRepository) {
//        return (args) -> {
//            logger.info("H2 uploadTest 测试开始...");
//
//            List<UploadInfo> uploadInfoList = uploadRepository.findAll();
//
//            uploadInfoList.forEach(uploadInfo -> logger.info(uploadInfo.toString()));
//            logger.info("H2 uploadTest 测试完成...");
//        };
//    }
}
